package com.xhxi.photobooker.websocket;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
//关键问题：@ServerEndpoint注解的类由Java WebSocket容器管理，而不是Spring容器管理，这导致：
//@Autowired注解无法正常工作
//无法直接注入Spring管理的Bean
//需要手动获取Spring容器中的服务
@Component
public class SpringContextHolder implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz) {
        return context.getBean(clazz);
    }
} 